{extend name="layout" /}
{block name="page"}
<div class="layui-card">
    <div class="tools">
        <div class="btns">
            <button class="layui-btn layui-btn-normal open" url="{:url('user/add')}">添加用户</button>
        </div>
        <div class="search">
            <form class="layui-form" method="get">
                <div class="layui-inline" style="width: 100px;">
                    <select name="type" lay-verify="type">
                        <option value="1" {eq name=":input('param.type')" value="1"}selected{/eq}>用户名</option>
                        <option value="2" {eq name=":input('param.type')" value="2"}selected{/eq}>id</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <input type="text" name="q" placeholder="请输查询要素" autocomplete="off" class="layui-input" value="{:input('param.q')}">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card-body">
        <table id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
{/block}
{block name="js"}
<script type="text/html" id="lockTpl">
    {{#  if(d.lock == 0){ }}
    <span>正常</span>
    {{# }else{ }}
    <span class="danger">锁定</span>
    {{# } }}
</script>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">编辑</a>
    {{# if(d.id>1){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
</script>
<script>
    layui.config({
        base: '__STATIC__/js/'
    }).use(['app'], function () {
        var app=layui.app;
        var table=layui.table;
        table.render({
            elem: '#dataTable'
            ,url: window.location.href //数据接口
            ,page: app.page_config //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:80}
                ,{field: 'username', title: '用户名', width:80}
                ,{field: 'role_name', title: '角色', width:135}
                ,{field: 'name', title: '姓名', width:135}
                ,{field: 'mobile', title: '手机', width: 180}
                ,{field: 'addtime', title: '添加时间', width: 150}
                ,{field: 'edit_password_time', title: '上次改密', width: 150}
                ,{title: '状态', width: 100,templet: '#lockTpl'}
                ,{field: 'lock_msg', title: '状态备注', width: 200}
                ,{title: '操作',width:220,toolbar:"#toolBar"}
            ]]
        });
        //监听工具条
        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'detail') {
                app.open('{:url("user/login_log")}?id=' + data.id, '查看登录日志：' + data.username);
            } else if (layEvent === 'del') {
                layer.confirm('真的要删除吗?', function (index) {
                    layer.close(index);
                    app.post({
                        id: data.id
                    }, 0, '{:url("user/del")}');
                });
            } else if (layEvent === 'edit') {
                app.open('{:url("user/edit")}?id=' + data.id, '编辑');
            }
        });
    });
</script>
{/block}